package algorithm.leetcode.I801to1000;

import algorithm.leetcode.TreeNode;

/**
 * 树的遍历
 */

public class Q938 {

    int sum = 0;

    public int rangeSumBST(TreeNode root, int low, int high) {
        inorderTraverse(root, low, high);
        return sum;
    }

    private void inorderTraverse(TreeNode node, int low, int high) {
        if (node == null) return;

        inorderTraverse(node.left, low, high);
        if (low <= node.val && node.val <= high) sum += node.val;
        inorderTraverse(node.right, low, high);
    }

}
